package com.um.jdy.common.finance.service.impl;

import cn.hutool.core.date.DateUtil;
import com.um.jdy.common.finance.enums.FinancialEnum;
import com.um.springboot.starter.utils.OrderUtil;

import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.finance.service.PlatformBillService;
import com.um.jdy.common.finance.dao.PlatformBillDao;
import com.um.jdy.common.finance.entity.po.PlatformBill;

/**
 * 服务实现类：平台流水表
 */
@Service
@Slf4j
public class PlatformBillServiceImpl extends BaseEntityServiceImpl<PlatformBillDao,PlatformBill>  implements PlatformBillService{

    /**
     * 保存账单
     * @param comId
     * @param outTradeNo
     * @param orderNo
     * @param amount
     * @param type
     * @param event
     * @param status
     * @return
     */
    public PlatformBill addBill(String comId, String outTradeNo, String orderNo, Integer amount, FinancialEnum.IncomeOrExpend type,
                                FinancialEnum.PlatformBillEvent event, FinancialEnum.BillStatus status){
        PlatformBill bill = new PlatformBill();
        bill.setComId(comId);
        bill.setNo(OrderUtil.getOrderNo());
        bill.setOutTradeNo(outTradeNo);
        bill.setOrderNo(orderNo);
        bill.setAmount(amount);
        bill.setType(type.name());//收入支出类型：0-收入，1-支出
        bill.setEvent(event.name());
        bill.setStatus(status.name());//账单状态：0未生效|1已生效|2已失效
        bill.setCreateTime(DateUtil.date());
        saveRow(bill);

        return bill;
    }
}
